<template>
	<view>
		首页
	</view>
</template>

<script>

export default {
	data() {
		return {
			banner: {},
			skeleton: true,
			countdown: 10,
			cardCur: 0,
			swiperList: [],
			towerStart: 0,
			direction: '',
			noticeList: [],
			homeInfo: {},
			showBtn: false,
			timer: null
		};
	},
	created() {
		this.getNoticeLis();
		this.getHomeInfo();
	},
	methods: {
		// 发送任务
		sendTask(status) {
			console.log(status)
			
			let me = this;
			if(status == 1) {
				uni.showToast({
					title:this.homeInfo.task.title
				})
			}
			if(status == 0) {
				me.openPopup('popup');
			}
			if(status == -1) {
			   uni.showModal({
			   	title: '提示',
			   	content: '确认匹配任务',
			   	success: function(res) {
					console.log(res)
			   		if (res.confirm) {
			   			me.post('/api/task/match').then(res => {
			   				if(res.code == 0) {
			   					me.openPopup('popup');
			   					me.timer = setInterval(function() {
			   						me.countdown--;
			   						if (me.countdown <= 0) {
			   							clearInterval(me.timer);
			   							me.showBtn = true;
			   						}
			   					}, 1000);
			   				}
			   			
			   			});
			   		}
			   	}
			   });	
			}
			
		},
		// /api/bulletin/lists
		async getNoticeLis() {
			const res = await this.get('/api/bulletin/lists');
			if(res.code == 0) {
				this.noticeList = res.data.data;
			}
		},
		async getHomeInfo() {
			const res = await this.get('/api/index');
			if(res.code == 0) {
				this.homeInfo = res.data;
				this.banner = res.data.banner
				this.countdown = res.data.task.countdown
			}
			
			this.skeleton = false
		},

		// 领取
		async receive() {
			let me = this;
			const res = await this.post('/api/task/receive');
			me.closePopup('popup');
			this.success(res, res.data.msg);
			me.getHomeInfo()
		}
	}
};
</script>

<style></style>
